<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>直接通过FormData</h2>
    <input type="file" multiple accept="image/*">
    <img src="" alt="">
    <button>上传</button>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        const ipt = document.querySelector('input')
        const btn = document.querySelector('button')
        const data1 = new FormData()
        ipt.addEventListener('change', function(e){
            data1.set('avatar', e.target.files[0])
        })
        btn.addEventListener('click', function(){
            axios({
                url : 'http://ajax-api.itheima.net/api/file',
                method : 'post' ,
                data : data1
            }).then((res) => {
                console.log(res.data.data.url)
                document.querySelector('img').src = res.data.data.url
            })
        })
    </script>
</body>
</html>